package com.imooc.mall.controller;

import com.github.pagehelper.PageInfo;
import com.imooc.mall.common.ApiRestResponse;
import com.imooc.mall.model.query.CreatOrderReq;
import com.imooc.mall.service.OrderService;
import com.imooc.mall.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单模块controller
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param
     * @return
     */
    @ApiOperation("创建订单功能")
    @PostMapping("/create")
    public ApiRestResponse create(@RequestBody CreatOrderReq createOrderReq){
        String s = orderService.create(createOrderReq);
        return ApiRestResponse.success(s);
    }

    /**
     * 订单详情展示功能
     */
    @ApiOperation("前台订单展示功能")
    @PostMapping("/detail")
    public ApiRestResponse detail(@RequestParam String orderNo ){
        OrderVO detail = orderService.detail(orderNo);
        return ApiRestResponse.success(detail);
    }

    /**
     * 前台订单分页列表
     */
    @ApiOperation("前台订单分页功能")
    @PostMapping("/list")
    public ApiRestResponse list(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize){

        PageInfo pageInfo = orderService.listForCustomer(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    /**
     * 前台取消订单接口
     */

    @ApiOperation("前台取消订单功能")
    @PostMapping("/cancel")
    public ApiRestResponse cancel(@RequestParam String orderNo){
        orderService.cancel(orderNo);
        return ApiRestResponse.success();
    }

    /**
     * 前台生成订单二维码的功能
     */
    @ApiOperation("生成订单二维码功能")
    @GetMapping("/qrcode")
    public ApiRestResponse qrcode(@RequestParam String orderNo){

        String qrcode = orderService.qrcode(orderNo);
        return ApiRestResponse.success(qrcode);
    }

    /**
     * 前台支付功能
     */
    @ApiOperation("支付功能")
    @PostMapping("/pay")
    public ApiRestResponse pay(@RequestParam String  orderNo){
        orderService.pay(orderNo);
        return ApiRestResponse.success();
    }

    /**
     * 后台
     */

}
